// group_admin/pages/testResult/testResult.js
Page({

  /**
   * json:
   * 0：题目
   * 1-4选项
   * 5：正确答案
   * 6：答案文字解析
   * 7：难度指数
   * 8：考点
   * 9：题型
   * 10：视频解析地址
   */
  data: {
    json:[],//接受页面传送的参数
    err:[],//接受答题信息
    myAccuracy:'',//正确率
    chooseValue:[],
    colllist:[],
    option:'',
    sheet:[],
    doSuccess:'0',
    doError:'0',
    doNull:'0',
    doCannot:'0',
    index:0,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.getParams();
    this.myAccuracy();//正确率
  },
  getParams:function(){
    const that = this;
    let eventChannel = this.getOpenerEventChannel();
    // 监听aishang事件，获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('json', function (json) {
      that.setData({
        json:json,
      })
      that.submitBtnHandle();//答题卡数据
    })
    eventChannel.on('err', function (err) {
      that.setData({
        err:err,
      })
    })

    eventChannel.on('chooseValue', function (chooseValue) {
      that.setData({
        chooseValue:chooseValue,
      })
      
    })

    eventChannel.on('colllist', function (colllist) {
      that.setData({
        colllist:colllist,
      })
    })

    eventChannel.on('parmas', function (parmas) {
      that.setData({
        parmas:parmas,
      })
    })
  },
  myAccuracy:function(){
    const that = this;
    var err = that.data.err;
    var point = 0;
    var doSuccess=0;
    var doError=0;
    var doNull=0;
    var doCannot=0;
    for(var i=0;i<err.length;i++){
      switch(err[i]){
        case 0:doSuccess++;continue;
        case 1:
        case 2:
        case 3:
        case 4:doError++;continue;
        case 'NAN':doNull++;
        default:doCannot++;
      }
    }
    point = doSuccess/err.length*100;
    that.setData({
      myAccuracy:point,
      doCannot:doCannot,
      doNull:doNull,
      doError:doError,
      doSuccess:doSuccess,
    })
  },
  ToKey:function(e){
    const that = this;
    var index = that.data.index;
    var title;
    if(index==0){
      title = e.currentTarget.dataset.title;
    }else{
      title = "全部解析"
    }
  
    wx.navigateTo({
      url: '../answerKey/answerKey',
      success: function(res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('json', that.data.json)
        res.eventChannel.emit('err', that.data.err)
        res.eventChannel.emit('chooseValue', that.data.chooseValue)
        res.eventChannel.emit('colllist', that.data.colllist)
        res.eventChannel.emit('title',title)
        res.eventChannel.emit('index',that.data.index)
        that.data.index=0;
      }
    })

  },
  ToTiKu:function(){
    const that = this;
    wx.navigateTo({
      url: '../tiku/tiku?parmas='+JSON.stringify(that.data.parmas)+'&url='+"/study/loadnewpaper",
    })
  },
    //答题卡
  submitBtnHandle: function() {
    const that = this;
    var sheets = [];
    for (var i = 0; i < that.data.json.length; i++) {
      sheets[i]=i+1;
    }
    that.setData({
     sheet: sheets,
    })
  },
  goIndexQuestion:function(e){
    const that = this;
    //判断你点击了哪道题
    var item = e.currentTarget.dataset.indexs;
    that.setData({
      index:item,
    })
    that.ToKey()
  }
})